var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);

document.getElementById( 'Thievery_YourThief'   ).innerHTML = prefService.getCharPref("extensions.Ultima.Thievery_YourThief"       );
document.getElementById( 'Thievery_YourRace'        ).value = prefService.getIntPref( "extensions.Ultima.Thievery_YourRace"        );
document.getElementById( 'Thievery_YourPersonality' ).value = prefService.getIntPref( "extensions.Ultima.Thievery_YourPersonality" );
document.getElementById( 'Thievery_YourThieves'     ).value = prefService.getIntPref( "extensions.Ultima.Thievery_YourThieves"     );
document.getElementById( 'Thievery_YourNetworth'    ).value = prefService.getIntPref( "extensions.Ultima.Thievery_YourNetworth"    );
document.getElementById( 'Thievery_YourTD'          ).value = prefService.getIntPref( "extensions.Ultima.Thievery_YourTD"          );
document.getElementById( 'Thievery_YourCrime'       ).value = prefService.getIntPref( "extensions.Ultima.Thievery_YourCrime"       );

document.getElementById( 'Thievery_EnemyThief'  ).innerHTML = prefService.getCharPref("extensions.Ultima.Thievery_EnemyThief"      );
document.getElementById( 'Thievery_EnemyNetworth'   ).value = prefService.getIntPref( "extensions.Ultima.Thievery_EnemyNetworth"   );
document.getElementById( 'Thievery_EnemyRelations'  ).value = prefService.getIntPref( "extensions.Ultima.Thievery_EnemyRelations"  );

document.getElementById( 'Thievery_Money'           ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Money"           );
document.getElementById( 'Thievery_Food'            ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Food"            );
document.getElementById( 'Thievery_Runes'           ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Runes"           );
document.getElementById( 'Thievery_Peasants'        ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Peasants"        );
document.getElementById( 'Thievery_Wizards'         ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Wizards"         );
document.getElementById( 'Thievery_Soldiers'        ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Soldiers"        );
document.getElementById( 'Thievery_OffSpecs'        ).value = prefService.getIntPref( "extensions.Ultima.Thievery_OffSpecs"        );
document.getElementById( 'Thievery_DefSpecs'        ).value = prefService.getIntPref( "extensions.Ultima.Thievery_DefSpecs"        );
document.getElementById( 'Thievery_Elites'          ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Elites"          );
document.getElementById( 'Thievery_Horses'          ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Horses"          );
document.getElementById( 'Thievery_Buildings'       ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Buildings"       );
document.getElementById( 'Thievery_Prisoners'       ).value = prefService.getIntPref( "extensions.Ultima.Thievery_Prisoners"       );

document.getElementById( 'Thievery_Operation'       ).value = prefService.getCharPref("extensions.Ultima.Thievery_Operation"       );

function addCommas(argNum, argThouSeparator, argDecimalPoint) {
var sThou = (argThouSeparator) ? argThouSeparator : ","
var sDec = (argDecimalPoint) ? argDecimalPoint : "."
var aParts = argNum.split(sDec)
var sInt = aParts[0] + sDec
var rTest = new RegExp("(\\d)(\\d{3}(\\" + sThou + "|\\" + sDec + "))")
while (sInt.match(rTest)) { sInt = sInt.replace(rTest, "$1" + sThou + "$2") }
aParts[0] = sInt.replace(sDec, "")
return aParts.join(sDec)
}

function Add_Commas(Number) { return addCommas( Number.toString() ); }

function ThiefMoney() {
document.getElementById( 'Thief_Money'              ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Money" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Stolen" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Steals gold from enemy coffers." ;
document.getElementById( 'Thievery_Operation'       ).value     = "RobtheVaults" ;
}

function ThiefFood() {
document.getElementById( 'Thief_Food'               ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Food" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Stolen" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Steals food from your opponent's storages." ;
document.getElementById( 'Thievery_Operation'       ).value     = "RobtheGranaries" ;
}

function ThiefRunes() {
document.getElementById( 'Thief_Runes'              ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Runes" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Stolen" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Steals runes from your target's wizards." ;
document.getElementById( 'Thievery_Operation'       ).value     = "RobtheTowers" ;
}

function ThiefPeasants() {
document.getElementById( 'Thief_Peasants'           ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Peasants" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Kidnapped" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Kidnaps peasants from your enemy and brings them to your province." ;
document.getElementById( 'Thievery_Operation'       ).value     = "Kidnapping" ;
}

function ThiefWizards() {
document.getElementById( 'Thief_Wizards'            ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Wizards" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Killed" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Attempts to assassinate enemy wizards to permanently weaken their ability to cast spells." ;
document.getElementById( 'Thievery_Operation'       ).value     = "AssassinateWizards" ;
}

function ThiefSoldiers() {
document.getElementById( 'Thief_Soldiers'           ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Soldiers" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Killed" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Assassinates a portion of your enemy's military, both at home and away." ;
document.getElementById( 'Thievery_Operation'       ).value     = "NightStrike" ;
}

function ThiefOffSpecs() {
document.getElementById( 'Thief_OffSpecs'           ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "OffSpecs" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Killed" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Assassinates a portion of your enemy's military, both at home and away." ;
document.getElementById( 'Thievery_Operation'       ).value     = "NightStrike" ;
}

function ThiefDefSpecs() {
document.getElementById( 'Thief_DefSpecs'           ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "DefSpecs" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Killed" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Assassinates a portion of your enemy's military, both at home and away." ;
document.getElementById( 'Thievery_Operation'       ).value     = "NightStrike" ;
}

function ThiefElites() {
document.getElementById( 'Thief_Elites'             ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Elites" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Killed" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Assassinates a portion of your enemy's military, both at home and away." ;
document.getElementById( 'Thievery_Operation'       ).value     = "NightStrike" ;
}

function ThiefHorses() {
document.getElementById( 'Thief_Horses'             ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Horses" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Stolen" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Steals an enemy's horses for your own use." ;
document.getElementById( 'Thievery_Operation'       ).value     = "StealHorses" ;
}

function ThiefBuildings() {
document.getElementById( 'Thief_Buildings'          ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Buildings" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Burnt" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Burns down enemy buildings to disrupt an enemy's stability." ;
if ( document.getElementById( 'Thievery_Operation'  ).value != "GreaterArson" ) document.getElementById( 'Thievery_Operation' ).value     = "Arson" ;
if ( document.getElementById( 'Thievery_Operation'  ).value == "GreaterArson" ) document.getElementById( 'Thievery_Info'      ).innerHTML = "A more powerful version of Arson, allows targetting of a specific type of building to burn down." ;
}

function ThiefPrisoners() {
document.getElementById( 'Thief_Prisoners'          ).checked   = true ;
document.getElementById( 'Thievery_Resource_Title'  ).innerHTML = "Prisoners" ;
document.getElementById( 'Thievery_Operation_Title' ).innerHTML = "Freed" ;
document.getElementById( 'Thievery_Info'            ).innerHTML = "Releases prisoners from an opponent's dungeons." ;
document.getElementById( 'Thievery_Operation'       ).value     = "FreePrisoners" ;
}

function Task_Thievery() {

var Thievery_Operation = document.getElementById( 'Thievery_Operation' ).value;

if ( Thievery_Operation == "RobtheVaults"       ) ThiefMoney() ;
if ( Thievery_Operation == "RobtheGranaries"    ) ThiefFood() ;
if ( Thievery_Operation == "RobtheTowers"       ) ThiefRunes() ;
if ( Thievery_Operation == "Kidnapping"         ) ThiefPeasants() ;
if ( Thievery_Operation == "AssassinateWizards" ) ThiefWizards() ;
if ( Thievery_Operation == "NightStrike"        ) if (( document.getElementById( 'Thief_OffSpecs' ).checked == false )&&( document.getElementById( 'Thief_DefSpecs' ).checked == false )&&( document.getElementById( 'Thief_Elites' ).checked == false )) ThiefSoldiers() ;
if ( Thievery_Operation == "StealHorses"        ) ThiefHorses() ;
if ( Thievery_Operation == "Arson"              ) ThiefBuildings() ;
if ( Thievery_Operation == "GreaterArson"       ) ThiefBuildings() ;
if ( Thievery_Operation == "FreePrisoners"      ) ThiefPrisoners() ;

if ( document.getElementById( 'Thievery_EnemyRelations' ).value != 0 ) {

if ( document.getElementById( 'Thievery_YourPersonality' ).value == 4 ) {
document.getElementById( 'Thief_Wizards_Name'  ).disabled = false ;
document.getElementById( 'Thievery_Wizards'    ).disabled = false ;
} else {
document.getElementById( 'Thief_Wizards_Name'  ).disabled = true ;
document.getElementById( 'Thievery_Wizards'    ).disabled = true ;
}

document.getElementById( 'Thief_Soldiers_Name' ).disabled = false ;
document.getElementById( 'Thief_OffSpecs_Name' ).disabled = false ;
document.getElementById( 'Thief_DefSpecs_Name' ).disabled = false ;
document.getElementById( 'Thief_Elites_Name'   ).disabled = false ;

document.getElementById( 'Thievery_Soldiers'   ).disabled = false ;
document.getElementById( 'Thievery_OffSpecs'   ).disabled = false ;
document.getElementById( 'Thievery_DefSpecs'   ).disabled = false ;
document.getElementById( 'Thievery_Elites'     ).disabled = false ;

} else {

document.getElementById( 'Thief_Wizards_Name'  ).disabled = true ;
document.getElementById( 'Thief_Soldiers_Name' ).disabled = true ;
document.getElementById( 'Thief_OffSpecs_Name' ).disabled = true ;
document.getElementById( 'Thief_DefSpecs_Name' ).disabled = true ;
document.getElementById( 'Thief_Elites_Name'   ).disabled = true ;

document.getElementById( 'Thievery_Wizards'    ).disabled = true ;
document.getElementById( 'Thievery_Soldiers'   ).disabled = true ;
document.getElementById( 'Thievery_OffSpecs'   ).disabled = true ;
document.getElementById( 'Thievery_DefSpecs'   ).disabled = true ;
document.getElementById( 'Thievery_Elites'     ).disabled = true ;

}

var Thievery_YourRace        = 0;
var Thievery_Resource        = 0;
var Thievery_Resources_Gains = 0;
var Thievery_Relative_NW     = 0;
var Thievery_WarBonus        = 1;
var Thievery_YourThieves     = 0;
var Thievery_YourNetworth    = 0;
var Thievery_EnemyNetworth   = 0;
var Thievery_Gains           = 0;
var Thievery_Losts           = 0;
var Thievery_Rate            = 0;
var Thievery_Max             = 0;
var Thievery_Optimal         = 0;
var Thievery_Penalty         = 0;
var Thief_Per_Resource       = 0;
var Thief_Max_Resource       = 0;

Thievery_YourRace      = Number( document.getElementById( 'Thievery_YourRace'      ).value );
Thievery_YourThieves   = Number( document.getElementById( 'Thievery_YourThieves'   ).value );
Thievery_YourNetworth  = Number( document.getElementById( 'Thievery_YourNetworth'  ).value );
Thievery_EnemyNetworth = Number( document.getElementById( 'Thievery_EnemyNetworth' ).value );

if ( document.getElementById( 'Thievery_EnemyRelations' ).value == 0 ) Thievery_Penalty = 1 - Thievery_Penalty_None       / 100 ;
if ( document.getElementById( 'Thievery_EnemyRelations' ).value == 1 ) Thievery_Penalty = 1 - Thievery_Penalty_Unfriendly / 100 ;
if ( document.getElementById( 'Thievery_EnemyRelations' ).value == 2 ) Thievery_Penalty = 1 - Thievery_Penalty_Hostile    / 100 ;
if ( document.getElementById( 'Thievery_EnemyRelations' ).value == 3 ) Thievery_Penalty = 1 - Thievery_Penalty_War        / 100 ;
if ( document.getElementById( 'Thievery_EnemyRelations' ).value == 4 ) Thievery_Penalty = 1 - Thievery_Penalty_OSW        / 100 ;

if ( Thievery_YourNetworth  > Thievery_EnemyNetworth ) Thievery_Relative_NW = Thievery_EnemyNetworth / Thievery_YourNetworth;
if ( Thievery_YourNetworth  < Thievery_EnemyNetworth ) Thievery_Relative_NW = Thievery_YourNetworth / Thievery_EnemyNetworth;
if ( Thievery_YourNetworth == Thievery_EnemyNetworth ) Thievery_Relative_NW = 1;

if ( Thievery_Operation == "RobtheVaults"                        ) { Thievery_Resources_Gains = 0.9 ; Thief_Per_Resource = Thief_Per_Resource_RobtheVaults         ; Thief_Max_Resource = Thief_Max_Resource_RobtheVaults         ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Money'     ).value );

if ( document.getElementById( 'Thievery_EnemyRelations' ).value == 3 ) Thievery_WarBonus = 1.9;

}
if ( Thievery_Operation == "RobtheGranaries"                     ) { Thievery_Resources_Gains = 0.9 ; Thief_Per_Resource = Thief_Per_Resource_RobtheGranaries      ; Thief_Max_Resource = Thief_Max_Resource_RobtheGranaries      ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Food'      ).value ); }
if ( Thievery_Operation == "RobtheTowers"                        ) { Thievery_Resources_Gains = 1   ; Thief_Per_Resource = Thief_Per_Resource_RobtheTowers         ; Thief_Max_Resource = Thief_Max_Resource_RobtheTowers         ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Runes'     ).value ); }
if ( Thievery_Operation == "Kidnapping"                          ) { Thievery_Resources_Gains = 0.8 ; Thief_Per_Resource = Thief_Per_Resource_Kidnapping           ; Thief_Max_Resource = Thief_Max_Resource_Kidnapping           ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Peasants'  ).value ); if ( document.getElementById( 'Thievery_EnemyRelations' ).value == 3 ) Thievery_WarBonus = 2; }
if ( Thievery_Operation == "AssassinateWizards"                  ) { Thievery_Resources_Gains = 1   ; Thief_Per_Resource = Thief_Per_Resource_AssassinateWizards   ; Thief_Max_Resource = Thief_Max_Resource_AssassinateWizards   ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Wizards'   ).value ); }
if ( Thievery_Operation == "StealHorses"                         ) { Thievery_Resources_Gains = 0.5 ; Thief_Per_Resource = Thief_Per_Resource_StealHorses          ; Thief_Max_Resource = Thief_Max_Resource_StealHorses          ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Horses'    ).value ); }
if ( Thievery_Operation == "Arson"                               ) { Thievery_Resources_Gains = 1   ; Thief_Per_Resource = Thief_Per_Resource_Arson                ; Thief_Max_Resource = Thief_Max_Resource_Arson                ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Buildings' ).value ); }
if ( Thievery_Operation == "GreaterArson"                        ) { Thievery_Resources_Gains = 1   ; Thief_Per_Resource = Thief_Per_Resource_GreaterArson         ; Thief_Max_Resource = Thief_Max_Resource_GreaterArson         ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Buildings' ).value ); }
if ( Thievery_Operation == "FreePrisoners"                       ) { Thievery_Resources_Gains = 1   ; Thief_Per_Resource = Thief_Per_Resource_FreePrisoners        ; Thief_Max_Resource = Thief_Max_Resource_FreePrisoners        ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Prisoners' ).value ); }

if ( Thievery_Operation == "NightStrike"                         ) {

if ( document.getElementById( 'Thief_Soldiers' ).checked == true ) { Thievery_Resources_Gains = 1   ; Thief_Per_Resource = Thief_Per_Resource_NightStrike_Soldiers ; Thief_Max_Resource = Thief_Max_Resource_NightStrike_Soldiers ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Soldiers'  ).value ); }
if ( document.getElementById( 'Thief_OffSpecs' ).checked == true ) { Thievery_Resources_Gains = 1   ; Thief_Per_Resource = Thief_Per_Resource_NightStrike_OffSpecs ; Thief_Max_Resource = Thief_Max_Resource_NightStrike_OffSpecs ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_OffSpecs'  ).value ); }
if ( document.getElementById( 'Thief_DefSpecs' ).checked == true ) { Thievery_Resources_Gains = 1   ; Thief_Per_Resource = Thief_Per_Resource_NightStrike_DefSpecs ; Thief_Max_Resource = Thief_Max_Resource_NightStrike_DefSpecs ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_DefSpecs'  ).value ); }
if ( document.getElementById( 'Thief_Elites'   ).checked == true ) { Thievery_Resources_Gains = 1   ; Thief_Per_Resource = Thief_Per_Resource_NightStrike_Elites   ; Thief_Max_Resource = Thief_Max_Resource_NightStrike_Elites   ; Thievery_Max = Thievery_Penalty * Thief_Max_Resource / 100 ; Thievery_Rate = Thievery_Max * Thief_Per_Resource ; Thievery_Resource = Number( document.getElementById( 'Thievery_Elites'    ).value ); }

}

Thievery_Optimal = Thievery_Resource * Thievery_Max / Thievery_Rate ;
if ( Thievery_Optimal > Thievery_YourThieves ) Thievery_Optimal = Thievery_YourThieves ;
Thievery_Gains = Math.round( Thievery_Optimal * Thievery_Relative_NW * Thievery_Rate * Thievery_WarBonus * Thievery_Resources_Gains );
Thievery_Losts = Math.round( Thievery_Optimal * Thievery_Relative_NW * Thievery_Rate * Thievery_WarBonus );

Thievery_Optimal = Math.round( Thievery_Optimal );

document.getElementById( 'Thievery_Relative_NW'     ).innerHTML = Math.round( Thievery_Relative_NW * 100 ) / 100 ;
document.getElementById( 'Thievery_Rate'            ).innerHTML = Math.round( Thievery_Rate * 100 ) / 100 ;
document.getElementById( 'Thievery_Max'             ).innerHTML = Math.round( Thievery_WarBonus * Thievery_Max * 10000 ) / 100 ;
document.getElementById( 'Thievery_Losts'           ).innerHTML = Math.round( ( 1 - Thievery_Resources_Gains ) * 10000 ) / 100 ;

document.getElementById( 'Thievery_Penalty'         ).innerHTML = Math.round( ( 1 - Thievery_Penalty ) * 100 );
document.getElementById( 'Thievery_Resources_Gains' ).innerHTML = Math.round( ( Thievery_Resources_Gains ) * 10000 ) / 100 ;
document.getElementById( 'Thief_Per_Resource'       ).innerHTML = Thief_Per_Resource;
document.getElementById( 'Thief_Max_Resource'       ).innerHTML = Thief_Max_Resource;

var List_Thieves = Thievery_YourThieves;

textonly = c0+ "Thievery Report Information" +cc+ Copyrights +
"<br />"+
"<br />"+c0+ "** Thief's Information **" +cc+
"<br />"+c1+ "Thieves: " +cc+c2+ Thievery_YourThieves +cc+
"<br />"+c1+ "Optimal Thieves: " +cc+c2+ Thievery_Optimal +cc+
"<br />"+c1+ "Networth: " +cc+c2+ Thievery_YourNetworth +cc+
"<br />"+
"<br />"+c0+ "** Defender's Information **" +cc+
"<br />"+c1+ "Networth: " +cc+c2+ Thievery_EnemyNetworth +cc+
"<br />"+
"<br />"+c0+ "** Operation Analysis **" +cc+
"<br />"+c1+ "Operation: " +cc+c2+ Thievery_Operation +cc+
"<br />"+c1+ "Resource Per Thief: " +cc+c2+ Thief_Per_Resource +cc+
"<br />"+c1+ "Thief Max Resource: " +cc+c2+ Thief_Max_Resource +cc+
"<br />"+c1+ "Penalty: " +cc+c2+ Thievery_Penalty +cc+
"<br />"+
"<br />";

for (i=1; i<=10; i++) {

document.getElementById( 'Thievery_Main_td'+i+'1' ).innerHTML = i ;
document.getElementById( 'Thievery_Main_td'+i+'2' ).innerHTML = Add_Commas( Thievery_Resource ) ;
document.getElementById( 'Thievery_Main_td'+i+'3' ).innerHTML = Add_Commas( Thievery_Optimal  ) ;
document.getElementById( 'Thievery_Main_td'+i+'4' ).innerHTML = Add_Commas( Thievery_Gains    ) ;
document.getElementById( 'Thievery_Main_td'+i+'5' ).innerHTML = Add_Commas( Thievery_Losts    ) ;

textonly = textonly + c1+ i +". "+ Add_Commas( Thievery_Resource ) +" - " +cc+c2+ Add_Commas( Thievery_Optimal ) +cc+c1+" thieves - " +cc+c2+ Add_Commas( Thievery_Gains ) +cc+c1+ " ("+Add_Commas( Thievery_Losts )+")"+cc+"<br />";
Thievery_Resource = Thievery_Resource - Thievery_Losts ;
Thievery_Optimal = Math.round( Thievery_Resource * Thievery_Max / Thievery_Rate );
if ( Thievery_Optimal > Thievery_YourThieves ) Thievery_Optimal = Thievery_YourThieves ;
Thievery_Gains = Math.round( Thievery_Optimal * Thievery_Relative_NW * Thievery_Rate * Thievery_WarBonus * Thievery_Resources_Gains );
Thievery_Losts = Math.round( Thievery_Optimal * Thievery_Relative_NW * Thievery_Rate * Thievery_WarBonus );

}

}

function YourThiefReport() {

//document.getElementById('CBtext2').innerHTML = textonly ;

textonly = textonly.replace(/\//g, "");
textonly = textonly.replace(/http:/g, "http://");
textonly = textonly.replace(/  /g, " / ");
textonly = textonly.replace(/<font color='#aa8822'>/g, "");
textonly = textonly.replace(/<font>/g, "");
textonly = textonly.replace(/<font color='#888888'>/g, "");
textonly = textonly.replace(/<font color='#ff0000'>/g, "");
textonly = textonly.replace(/<font>/g, "");
//textonly = textonly.replace(/<br >/g, "bijoforever");

//document.Calculator2.CBtext1.value = textonly;
//copy(document.Calculator2.CBtext1.value);

}

function YourThiefReset(){

document.getElementById( 'Thievery_YourThief'       ).innerHTML = "Thief's Information" ;
document.getElementById( 'Thievery_YourRace'        ).value = 0 ;
document.getElementById( 'Thievery_YourPersonality' ).value = 0 ;
document.getElementById( 'Thievery_YourThieves'     ).value = 0 ;
document.getElementById( 'Thievery_YourNetworth'    ).value = 0 ;
document.getElementById( 'Thievery_YourTD'          ).value = 0 ;
document.getElementById( 'Thievery_YourCrime'       ).value = 0 ;

}

function EnemyThiefReset(){

document.getElementById( 'Thievery_EnemyThief'      ).innerHTML  = "Defender's Information" ;
document.getElementById( 'Thievery_EnemyNetworth'   ).value = 0 ;
document.getElementById( 'Thievery_EnemyRelations'  ).value = 0 ;

}

function ThiefResetAll(){

YourThiefReset();
EnemyThiefReset();
ThiefMoney();

document.getElementById( 'Thievery_Money'           ).value = 0 ;
document.getElementById( 'Thievery_Food'            ).value = 0 ;
document.getElementById( 'Thievery_Runes'           ).value = 0 ;
document.getElementById( 'Thievery_Peasants'        ).value = 0 ;
document.getElementById( 'Thievery_Wizards'         ).value = 0 ;
document.getElementById( 'Thievery_Soldiers'        ).value = 0 ;
document.getElementById( 'Thievery_OffSpecs'        ).value = 0 ;
document.getElementById( 'Thievery_DefSpecs'        ).value = 0 ;
document.getElementById( 'Thievery_Elites'          ).value = 0 ;
document.getElementById( 'Thievery_Horses'          ).value = 0 ;
document.getElementById( 'Thievery_Buildings'       ).value = 0 ;
document.getElementById( 'Thievery_Prisoners'       ).value = 0 ;

}

function SaveAllValues() {

prefService.setCharPref('extensions.Ultima.Thievery_YourThief'       , document.getElementById( "Thievery_YourThief"   ).innerHTML );
prefService.setIntPref( 'extensions.Ultima.Thievery_YourRace'        , document.getElementById( "Thievery_YourRace"        ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_YourPersonality' , document.getElementById( "Thievery_YourPersonality" ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_YourThieves'     , document.getElementById( "Thievery_YourThieves"     ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_YourNetworth'    , document.getElementById( "Thievery_YourNetworth"    ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_YourTD'          , document.getElementById( "Thievery_YourTD"          ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_YourCrime'       , document.getElementById( "Thievery_YourCrime"       ).value );

prefService.setCharPref('extensions.Ultima.Thievery_EnemyThief'      , document.getElementById( "Thievery_EnemyThief"  ).innerHTML );
prefService.setIntPref( 'extensions.Ultima.Thievery_EnemyNetworth'   , document.getElementById( "Thievery_EnemyNetworth"   ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_EnemyRelations'  , document.getElementById( "Thievery_EnemyRelations"  ).value );

prefService.setIntPref( 'extensions.Ultima.Thievery_Money'           , document.getElementById( "Thievery_Money"           ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_Food'            , document.getElementById( "Thievery_Food"            ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_Runes'           , document.getElementById( "Thievery_Runes"           ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_Peasants'        , document.getElementById( "Thievery_Peasants"        ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_Wizards'         , document.getElementById( "Thievery_Wizards"         ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_Soldiers'        , document.getElementById( "Thievery_Soldiers"        ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_OffSpecs'        , document.getElementById( "Thievery_OffSpecs"        ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_DefSpecs'        , document.getElementById( "Thievery_DefSpecs"        ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_Elites'          , document.getElementById( "Thievery_Elites"          ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_Horses'          , document.getElementById( "Thievery_Horses"          ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_Buildings'       , document.getElementById( "Thievery_Buildings"       ).value );
prefService.setIntPref( 'extensions.Ultima.Thievery_Prisoners'       , document.getElementById( "Thievery_Prisoners"       ).value );

prefService.setCharPref('extensions.Ultima.Thievery_Operation'       , document.getElementById( "Thievery_Operation"       ).value );

}

function Task_Manager() {
Task_Thievery();
SaveAllValues();
setTimeout("Task_Manager()",1);
}

Task_Manager();